//package com.jusda.advice;
//
//import com.fasterxml.jackson.core.JsonProcessingException;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.core.MethodParameter;
//import org.springframework.http.MediaType;
//import org.springframework.http.converter.HttpMessageConverter;
//import org.springframework.http.server.ServerHttpRequest;
//import org.springframework.http.server.ServerHttpResponse;
//import org.springframework.web.bind.annotation.ControllerAdvice;
//import org.springframework.web.bind.annotation.ExceptionHandler;
//import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
//
///**
// * @Author yiyi
// * @Date 2022/3/14-上午9:51
// * @Description:
// */
//@ControllerAdvice(basePackages = "com.jusda")
//@Slf4j
//public class ExceptionAdvice implements ResponseBodyAdvice<Object> {
//
//
//    @Override
//    public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
//        return true;
//    }
//
//    @Override
//    public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
//        if (body instanceof ApiResult) {
//            return body;
//        }
//        ObjectMapper objectMapper = new ObjectMapper();
//        ApiResult<Object> result = ApiResult.success(body);
//        if (body instanceof String) {
//            try {
//                objectMapper.writeValueAsString(body);
//                response.getHeaders().add("Content-Type", "application/json");
//                return request;
//            } catch (JsonProcessingException e) {
//                log.error("序列化错误:", e);
//            }
//        }
//        return result;
//    }
//
//    @ExceptionHandler(Exception.class)
//    public ApiResult handlerException(Exception e){
//       return ApiResult.fail(false,"0",e.getMessage());
//    }
//}
